<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>子传父</title>
		<script src="js/vue.js" type="text/javascript" charset="utf-8"></script>
	</head>
	<body>
		<div id="app">
			<child @myevent="getData"></child>
		</div>
		<script type="text/javascript">
			Vue.component("child",{
				template:`
					<div style="background:blue;color:white;">
						子组件--<button @click="sendData">点击传递数据给父组件</button>
					</div>
				`,
				methods:{
					sendData(){
						this.$emit("myevent",{
							childdata:"儿子的信息"
						})
					}
				}
			})
			const vm = new Vue({
				el:"#app",
				data:{
					cd:""
				},
				methods:{
					getData(res){
						console.log("子组件的信息：",res);
						this.cd = res.childdata;
						console.log(this.cd);
					}
				}
			})
		</script>
	</body>
</html>
